﻿/**
* Boxy 0.1.4 - Facebook-style dialog, with frills
*
* (c) 2008 Jason Frame
* Licensed under the MIT License (LICENSE)
* jQuery plugin
*
* Options:
*   message: confirmation message for form submit hook (default: "Please confirm:")
*
* Any other options - e.g. 'clone' - will be passed onto the boxy constructor (or
* Boxy.load for AJAX operations)
* 可以在弹出的页面里运行 Javascript脚本。但是不能引用外部文件。
*
*/

//
// Boxy Class
//需地改造这个控件。 把它改造成一个 jquery 控件。改名为： Layer
//ask , alert , confirm 移到 jv 下面去。


(function ($) {

  jv.getDomPath = function (a) {
    return a;
  }
  jv.getEyeSize = function (doc) {
    var size = {};

    var d = (doc && doc.documentElement) || document.documentElement;
    size = {width: d.clientWidth, height: d.clientHeight};

    //有时，取高度为0.
    if (!size.height) {

    }
    return size;
  }

  //使居中。
  //axis = x or  y
  $.fn.getSuitPosition = function (offset) {
    var size = jv.getEyeSize();
    offset = offset || {left: 10, top: 10};
    return {
      left: Math.max((size.width - this.outerWidth()) / 2, offset.left),
      top: Math.max((size.height - this.outerHeight()) / 2, offset.top)
    };
  }






  var fnName = "Boxy";
    jv.initMyPlugin(fnName, create );

    function create(target,ev) {
        var $target = $(target);

        var p = $target.data(fnName);

        if (!p.divId) {
            p.divId = jv.random();
        }
        $(".BlurHide").hide();

        //openerDoer 特别不稳定，很容易销毁，保存一个 page对象。

        var openerEvent = { originalEvent: "jquery", target: document.documentElement };

        $target
            .empty()
            .data("openerEvent", openerEvent)
            .addClass("openerEvent temp " + (p.css || p.css))
            .append('<div class=dragDiv></div><div class="title-bar"><span class="title"></span><div class="tool"></div><div class="boxy-close button view"></div></div><div class="boxy-content"></div>')
            .Boxy("setupTitleBar")

        if (p.html) {
            $target.Boxy("setContent", p.html);
        }

        //把 class=tool 移到 title 上去。
        var $content = $target.find(">.boxy-content");
        var tol = $content.find(".tool:first");
        tol.children().appendTo($target.find(">.title-bar>.tool").addClass(tol.attr("class")));
        tol.remove();

        if (p.footer) {
            $target.append("<div class='boxy-footer'>" + p.footer + "</div>");
        }
        else {
            $content.addClass("boxy-bottom");
        }

        if (p.width) $content.css("width", p.width);
        if (p.height) $content.height(p.height);

        $target.Boxy("show", 0);

        var size = jv.getEyeSize();

        $content.css(
            {
                maxWidth: size.width,
                maxHeight: size.height - jv.PaddingTop - jv.PaddingBottom - (18 + $target.find(".title-bar").outerHeight() + $target.find(".boxy-footer").outerHeight())
            });

        if ($.fn.bindResize) {
            $target.find(".dragDiv").bindResize({
                down: function (self, e, data) {
                    $(self).parent().css("width", "auto");
                    data.width = $(self).parent().find(">.boxy-content").width();
                    data.height = $(self).parent().find(">.boxy-content").height();
                    data.screenX = e.screenX;
                    data.screenY = e.screenY;
                },
                move: function (self, e, data) {
                    $(self).parent().find(">.boxy-content").css(
                        {
                            width: data.width + (e.screenX - data.screenX),
                            height: data.height + (e.screenY - data.screenY)
                        });
                },
                up: function (self, e) {
                    $(self).parent().reFith();
                }
            });
        }
    }

    $.fn.Boxy.defaults = {
        afterHide: false,
        beforeHide: false,
        beforeShow: false,
        center: true,           // center dialog in viewport?
        clickToFront: false,           // bring dialog to foreground on any click (not just titlebar)?    };
        clone: false,          // clone content prior to insertion into dialog?
        closeable: true,           // display close link in titlebar?
        closeButton: false,    //默认按钮, 即用户点关闭时, 要点击的按钮.
        css: "",
        draggable: true,           // can this dialog be dragged?
        fixed: true,           // use fixed positioning, if supported? absolute positioning used otherwise
        height: "",         //关于 height,可以是 auto 或 "" 表示不设置高度，移除  content 子元素的 fith.
        hideAnimateTime: 0,
        html: "",       //内容
        modal: true,          // make dialog modal?
        moveHandle: ">.title-bar",
        onClose: false,
        onChange: false,
        opacity: 0.5,
        title: "",           // titlebar text. titlebar will not be visible if not set.
        width: ""
    };

    $.fn.Boxy.methods = {
        options: function ($target) {
            return $target.data("Boxy");
        },


        // Returns a jQuery object wrapping the boxy content region.
        // This is the user-editable content area (i.e. excludes titlebar)
        getContent: function ($target) {
            return $target.find('>.boxy-content');
        },

        // jQuery Dom  或者 文本  或者 数组
        setContent: function ($target, newContent) {

            var content = $target.find(">.boxy-content");//this.getContent($target);
            content.empty();
            if (newContent.jquery && newContent.html) {
                content.append(newContent);
            }
            else {
                if (jv.getType(newContent.length) == "array") {
                    for (var i = 0, len = newContent.length; i < len; i++) {
                        content.append(newContent[i]);
                    }
                }
                else {
                    content.append(newContent);
                }
            }

            var p = $target.Boxy("options");

            if (p && p.height == "auto") {
                content.children().removeClass("fith");
            }
        },



        // Center this dialog in the viewport
        // axis is optional, can be 'x', 'y'.
        center: function ($target, speed) {
            $target.Boxy("toTop");
            var pos = $target.getSuitPosition();
            if (jv.isNull(speed)) { speed = 100; }
            $target.finish().css({ left: pos.left }).animate({ left: pos.left + "px", top: pos.top + "px", opacity: 1 }, speed);//{ opacity: 0, left: pos.left + "px", top: pos.top + 300 + "px" }).animate(, speed);
            return $target;
        },
        // Make this boxy instance visible
        show: function ($target, speed) {
            var p = $target.Boxy("options");
            if (p.beforeShow) {
                if (p.beforeShow.call($target[0]) === false) return false;
            }

            if (p.modal) {
                if (!$("#" + p.divId).length) {
                    $(document.body).append('<div id="' + p.divId + '" class="boxy-modal-blackout"></div>');
                }

                $("#" + p.divId).css({ zIndex: Boxy._nextZ() });
            }

            $target.Boxy("toTop");
            var pos = $target.getSuitPosition();
            //if (jv.isNull(speed)) { speed = 100; }
            $target.finish()/*.css({ opacity: 0, left: pos.left + "px", top: pos.top + 300 + "px" })*/.show().css({ left: pos.left + "px", top: pos.top + "px", opacity: 1 });//, speed);


            if (p.afterShow) {
                p.afterShow.call($target[0]);
            }

            return $target;
        },
        hide: function ($target) {
            var p = $target.Boxy("options");

            if (p.beforeHide && (p.beforeHide.call($target[0]) === false)) {
                return false;
            }

            if (p.hideAni) {
                p.hideAni.call($target[0]);
            } else {
                $target.hide();
            }

            if (p.modal) {
                $("#" + p.divId).hide();
            }


            try {
                if (p.afterHide) {
                    p.afterHide.call(jv.me(containerEv), dataChanged, containerEv);
                }
            }
            catch (e) {
                jv.say(e);
            }
            return $target;
        },


        // Hide this boxy instance
        bye: function ($target, setting) {
            var p = $.extend({}, $target.Boxy("options"), setting);

            if ($target.Boxy("hide") === false) return false;

            var me = jv.me(page),
                page = $(me.target),
                page_changed = page.attr("data-changed"),
                dataChanged = false;

            if (!jv.isNull(me.dataChanged)) {
                dataChanged = jv.getBool(me.dataChanged);
            } else if (!jv.isNull(page_changed)) {
                dataChanged = jv.getBool(page_changed);
            }

            var domPath = jv.getDomPath($target[0]);
            if (me.domPath == domPath) {
                jv.unloadRequest(me);
            }

            var containerEv = $target.data("openerEvent");

            try {
                if (dataChanged && p.onChange) {
                    p.onChange.call(jv.me(containerEv), { refresh: dataChanged }, page, containerEv);
                }

                if (p.onClose) {
                    p.onClose.call(jv.me(containerEv), { refresh: dataChanged }, page, containerEv);
                }
            }
            catch (e) {
                jv.say(e);
            }

            $target.next(".boxy-modal-blackout").remove();
            $target.remove();
            return;
        },

        resize: function ($target, p) {
            $target.find(">.boxy-content")
                .css(p);
            //$target.css({ width: $target.width() + 20 });
            //.css("width", p.width)
            //.outerHeight(p.height);

            //if (p.center) {
            //    $target.Boxy("center");
            //}

            return $target;
        },

        // Move this dialog box above all other boxy instances
        toTop: function ($target) {
            return $target.css({ zIndex: Boxy._nextZ() });
        },

        //content 的高度和宽度，要减去外面的间隙。
        viewport: function ($target, p) {
            var p = p || $target.Boxy("options");

            var retSize = jv.getEyeSize();
            retSize.maxWidth = retSize.width = retSize.width - 18;
            retSize.maxHeight = retSize.height = retSize.height - jv.PaddingTop - jv.PaddingBottom - 18 - $target.find(".title-bar").outerHeight() - $target.find(".boxy-footer").outerHeight();

            if (p.maxWidth) {
                retSize.maxWidth = Math.min(p.maxWidth, retSize.maxWidth);
            }
            if (p.maxHeight) {
                retSize.maxHeight = Math.min(p.maxHeight, retSize.maxHeight);
            }
            if (p.minWidth) {
                retSize.minWidth = p.minWidth;
            }
            if (p.minHeight) {
                retSize.minHeight = p.minHeight;
            }

            if (p) {
                if (p.width === 0) {
                }
                else if (p.width == "auto" || !p.width) {
                    retSize.width = "";
                }
                else if (p.width < 0) {
                    retSize.width = Math.min(retSize.width + p.width * 2, retSize.width);
                }
                else {
                    retSize.width = Math.min(p.width, retSize.width);
                }

                if (p.height === 0) {
                }
                else if (p.height == "auto" || !p.height) {
                    retSize.height = "";
                    //bxy.getInner().css("maxHeight", retSize.height + "px");
                }
                else if (p.height < 0) {
                    retSize.height = Math.min(retSize.height + p.height * 2, retSize.height);
                }
                else {
                    retSize.height = Math.min(p.height, retSize.height);
                }
            }
            return retSize;
        },
        setTitle: function ($target, title) {
            var p = $target.Boxy("options");
            p.title = title;
            return $target.find(".title-bar .title").html(title);
        },
        setupTitleBar: function ($target) {
            var p = $target.Boxy("options");

            $target.find(".title-bar .title").html(p.title);

            if (!p.closeable) {
                $target.find(".title-bar .boxy-close").hide();
            } else {
                $target.reBind('keypress.boxy', function (evt) {
                    var key = evt.which || evt.keyCode;
                    if (key == 27) {
                        $(this).Boxy("bye");
                    }
                });
            }

            if (p.draggable && $.fn.bindResize) {
                (p.moveHandle ? $target.find(p.moveHandle) : $target).bindResize({
                    pre: function (self, e, data) {
                        var doer = e.target;
                        if (doer.tagName.indexFrom("input", "button") >= 0) return false;
                        if (doer.className.indexOf("button") >= 0) return false;
                    },
                    down: function (self, e, data) {
                        $(self).addClass("dragging");
                        $target.Boxy("toTop");
                        data.o = { left: jv.getInt($target.css("left")), top: jv.getInt($target.css("top")) };
                        data.mousePos = { left: e.clientX, top: e.clientY };
                    },
                    move: function (self, e, data) {
                        $target.css({ left: e.clientX - data.mousePos.left + data.o.left, top: e.clientY - data.mousePos.top + data.o.top });
                    },
                    up: function (self, e, data) {
                        $(self).removeClass("dragging");
                        $(".BlurHide").hide();

                        var pos = { left: e.clientX - data.mousePos.left + data.o.left, top: e.clientY - data.mousePos.top + data.o.top };
                        var rePos = false, eyeSize = jv.getEyeSize(), boxWidth = $target.width(), pw = 50;

                        if (pos.left + pw > eyeSize.width) {
                            pos.left = eyeSize.width * 2 / 3;
                            rePos = true;
                        }

                        if (pos.top + pw > eyeSize.height) {
                            pos.top = eyeSize.height * 2 / 3;
                            rePos = true;
                        }

                        if (pos.left + boxWidth < pw + 50) {
                            pos.left = 0 - boxWidth * 2 / 3;
                            rePos = true;
                        }

                        if (pos.top < 0) {
                            pos.top = 0;
                            rePos = true;
                        }

                        if (rePos) {
                            $target.css(pos);
                        }

                        return;
                    }
                });
            }

            $target.find(">.title-bar .boxy-close").reBind("click", function (ev) {
                ev.stopPropagation();
                if (p.beforeClose && (p.beforeClose.call(this) === false)) {
                    return false;
                }
                $target.Boxy("bye");
                return;
            });

            return $target;
        }
    };


})(jQuery);

//第一个参数是保存的参数，第二个参数是马上要显示的参数。
function Boxy(options) {
    options = options || {};
    options.boxyId = options.boxyId || jv.random();
    $(document.body).append("<div class='boxy-wrapper' id='" + options.boxyId + "' style='display:none;'></div>");

    return $("#" + options.boxyId).Boxy(options);
};

Boxy.EF = function () { };


Boxy.resizeConfigured = false;
Boxy.dragging = null;

Boxy.load = function (options) {
    options = options || {};
    var url = options.url, LoadedCallBack = options.callback || options.LoadedCallBack;

    var bxy = new Boxy($.extend({ minWidth: 480 }, options, {
        //加载远程，增加动画
        html: "<div class='loading'></div>", width: "auto", height: "auto"
    })).hide();

    var options = bxy.Boxy("options");

    bxy.delay(200).fadeIn(300);

    if (!url) {
        bxy.fadeIn(200);
        if (LoadedCallBack) LoadedCallBack(bxy);
        return bxy;
    }

    if (options.iframe) {
        //bxy.css({
        //    left: -3000, top: -3000
        //});//.moveToX(-3000).moveToY(-3000);

        //.addClass("openPage");
        bxy.Boxy("resize", bxy.Boxy("viewport"));
        bxy.Boxy("show", 0);

        //.width(retSize.width)
        //.height(retSize.height);
        //<style>html,body{overflow:hidden;}</style>
        bxy.Boxy("setContent", '<iframe src="' + url + '" style="padding:0px;margin:0px;border-width:0px;width:100%;height:99%;"/>', options);

        return bxy;
    }

    //重新设置接收 Reqeust信号.
    bxy.addClass("jvRequest_waite");

    var ajax = {
        url: url, type: 'GET', dataType: 'html', cache: false,
        //beforeSend: function (xhr) {
        //    //记录弹出Boxy 的源.
        //    //bxy.boxy.data("srcForBoxy", jv.FindNotTempDialogSrc(jv.getDoer()));
        //    jv.createEventSource(xhr, bxy[0]);
        //},
        success: function (html) {
            jv.setDoer(bxy[0]);

            var oriHtml = html;
            if (jv.hasValue(html) == false) {
                bxy.find(">.boxy-content").html("<span style='color:red'>没有内容！</span>");
                return;
            }
            else if (html.charAt(0) == '{') {
                var res = null;
                try {
                    res = $.parseJSON(html);
                }
                catch (e) {
                }
                if (res && res.msg) {
                    bxy.Boxy("setContent", "<div style='padding:20px'><div style='color:red'>" + res.msg + "</div></div>");
                    bxy.Boxy("show", 0);
                    return;
                }
            }

            if (options["loading"]) options["loading"](bxy);

            bxy.removeClass("temp");

            var oriHtml = html;
            html = $(oriHtml);

            var htmlFilter = jv.myFilter(html, options.filter, bxy.getDomPath());

            //bxy.css({ opacity: 0 });

            jv.execHtml(htmlFilter.preJs, {
                originalEvent: true, target: bxy[0]
            });

            var ta = jv.me(bxy[0]);
            if (ta && ta.size) {
                $.extend(options, ta.size);

                jv.procPopConfig(options);
            }

            var pageTitle = $(html).filter("title").html() || jv.findTitle(oriHtml) || "";
            //ie8 会把 title 过滤掉。
            if (pageTitle) {
                var oriTitle = bxy.find(".title-bar .title");
                var oriHtml = oriTitle.html();
                var tits = [];
                if (options.title) {
                    tits.push(options.title);
                }
                if (oriHtml) {
                    tits.push(oriHtml);
                }

                tits.push(pageTitle);

                tits = tits.distinct(function (a, b) {
                    return a.indexOf(b) >= 0;
                });

                pageTitle = tits.join(" ");

                oriTitle.html(pageTitle);
            }

            jv.log(pageTitle || options.title, options.url);

            //htmlFilter.doms.push("<style>html,body{overflow:hidden;}</style>");

            bxy.css({ left: "0px", top: "0px" }).Boxy("setContent", htmlFilter.doms);

            var contentDiv = bxy.find(">.boxy-content"), tol = contentDiv.find(".tool:first");
            tol.children().appendTo(bxy.find(".title-bar>.tool").addClass(tol.attr("class")));
            tol.remove();

            var retSize = bxy.Boxy("viewport");

            //重设置
            //contentDiv.css({
            //    maxWidth: retSize.maxWidth
            //}).css({
            //    maxHeight: retSize.maxHeight
            //});

            bxy.Boxy("resize", retSize);

            var children = contentDiv.children();

            var contentDivCount = 0, contentDivIndex = 0;
            for (var i = 0, len = children.length; i < len; i++) {
                if (children[i].tagName.indexFrom("link", "style") >= 0) {
                    continue;
                }
                if (!contentDivCount) {
                    contentDivIndex = i;
                }
                contentDivCount++;
            }

            if (contentDivCount == 1) {
                children.eq(contentDivIndex).addClass("fith");
            }


            //可能有图片，需要远程加载，远程加载完成之后，再center
            bxy.Boxy("show", 0);

            //执行完Show之后，再执行Js，可以在Js中操作该Boxy
            jv.execHtml(htmlFilter.lastJs, {
                originalEvent: true, target: bxy[0]
            });

            //setTimeout(function () {
            //    bxy.Boxy("center");
            //}, 250);

            //bxy;
            if (LoadedCallBack) LoadedCallBack.call(bxy[0], oriHtml);
        },
        error: function (ev) {
            var msg = jv.getErrorFromPage(ev.responseText) || "服务器出现错误!";

            var loginIndex = msg.indexOf("登录");
            if (loginIndex >= 0) {
                msg = msg.slice(0, loginIndex) + '<a class="Link" onclick="javascript:top.document.location=' + (jv.url().root) + 'Login"> 登录 </a>' + msg.slice(loginIndex + 2);
            }

            var msg = '<div><div class="question" style="color:red"><div class="icon err" /> <p class="Wrap">'
            + msg +
                    '</p></div><div class="answers">请检查数据正确性,或联系运维管理员.</div></div>';

            bxy.Boxy("setContent", msg);

            bxy.Boxy("show");
            //if (options.autoShow) {
            //}
        }
    };


    jQuery.ajax(ajax);

    return bxy;
};
Boxy.loadCard = function (p) {
    if (!p.width || !p.height) {
        var jUrl = jv.url(p.url), urlsects = jUrl.url.substr(jUrl.root.length).split("/");
        p.area = urlsects[0];
        p.controller = urlsects[1];
        p.action = urlsects[2];

        //var whConfig = jv.PopCardConfig(p.area, p.controller, p.action);

        //if (jv.isNull(p.width)) {
        //    p.width = whConfig[0];
        //}

        //if (jv.isNull(p.height)) {
        //    p.height = whConfig[1];
        //}
    }

    return Boxy.load(p);
};
Boxy.loadList = function (op) {
    if (!p.width || !p.height) {
        var jUrl = jv.url(p.url), urlsects = jUrl.url.substr(jUrl.root.length).split("/");
        p.area = urlsects[0];
        p.controller = urlsects[1];
        p.action = urlsects[2];

        //var whConfig = jv.PopListConfig(p.area, p.controller, p.action);

        //if (jv.isNull(p.width)) {
        //    p.width = whConfig[0];
        //}

        //if (jv.isNull(p.height)) {
        //    p.height = whConfig[1];
        //}
    }

    return Boxy.load(p);
};

Boxy.show = function () {
    return (Boxy.get() || $()).Boxy("show");
}

Boxy.bye = function () {
    return (Boxy.get() || $()).Boxy("bye");
}

//取当前事件源的Boxy
Boxy.get = function (dom) {
    var doer = dom || jv.getDoer();
    if (doer) {
        var bxy = $(doer).closest(".boxy-wrapper");
        if (bxy.length) {
            return bxy;
        }
    }

    return Boxy.getTop();
}

//模态获取最上层的 Boxy
Boxy.getTop = function () {
    var mx = 0,
     mb = null;

    var con = $(".boxy-wrapper");

    con.each(function () {
        if (this.style.display == "none") return;
        var self = $(this);
        var zIndex = jv.getInt(self.css("zIndex"));
        if (zIndex > mx) {

            if (self.hasClass("Ignore")) {
                return true;
            }

            mx = zIndex;
            mb = this;
        }
    });


    if (mb) return $(mb);
    //if (!bod) bod = window;
    //if (bod.parent && bod != bod.parent) {
    //    return Boxy.getOne(bod.parent);
    //}
    return null;
};

Boxy.confirm = function (msg, title, callback,cancelCallback) {
    return Boxy.html({
        html: "<div class='boxy-msg wrap htmlPad icon'>" + msg + "</div>",
        footer: "<input type=button value='确定' class='btnOK' /><input type=button value='取消' class='btnCancel' />",
        title: title || '请确认',
        callback: function (bxy) {
            //默认值是 false ,在窗体关闭的时候
            bxy.find(".btnOK").bind("click", bxy, function (ev) {
                var bxy = ev.data;
                //确定时，返回里面的Json数据。
                // if (bxy.chk() == false) {
                //     return false;
                // }
                if (callback) {
                    var evOpener = bxy.data("openerEvent");
                    if (callback.call(jv.me(evOpener), bxy.getDivJson(), bxy, evOpener) === false) {
                        return false;
                    }
                }
                bxy.Boxy("bye");
            });
            bxy.find(".btnCancel").bind("click", bxy, function (ev) {
                var bxy = ev.data;
                if (cancelCallback) {
                    var evOpener = bxy.data("openerEvent");
                    if(cancelCallback.call(jv.me(evOpener), null, bxy, evOpener) === false) {
                        return false;
                    }
                }
                bxy.Boxy("bye");
            });

            bxy.find("input:first").focus();
        }
    }).addClass("confirm");
};
Boxy.prompt = function (msg, defValue, title, callback) {
    msg = msg || "";
    defValue = defValue || "";

    return Boxy.html({
        html: "<div class='boxy-msg wrap htmlPad icon'><span class='key'>" + msg + "</span><textarea class=val style='width:320px;height:120px;'>" + jv.encode(defValue) + "</textarea></div>",
        footer: "<input type=button value='确定' class='btnOK' /><input type=button value='取消' class='btnCancel' />",
        title: title || '请输入',
        callback: function (bxy) {
            //默认值是 false ,在窗体关闭的时候
            bxy.find(".btnOK").bind("click", bxy, function (ev) {
                ev.stopPropagation();

                var bxy = ev.data;
                if (callback) {
                    var evOpener = bxy.data("openerEvent");

                    if (callback.call(jv.me(evOpener), bxy.find("textarea").val(), bxy, evOpener) === false) {
                        return false;
                    }
                }
                bxy.Boxy("bye");
            });
            bxy.find(".btnCancel").bind("click", bxy, function (ev) {
                ev.stopPropagation();

                var bxy = ev.data;
                if (callback) {
                    var evOpener = bxy.data("openerEvent");
                    if (callback.call(jv.me(evOpener), null, bxy, evOpener) === false) {
                        return false;
                    }
                }
                bxy.Boxy("bye");
            });

            bxy.find("input:first").focus();
        }
    }).addClass("prompt");
};
Boxy.error = function (msg, title, callback) {
    Boxy.ask(msg, title || "错误", callback).addClass("err");
};

Boxy.alert = function (msg, title, callback) {
    Boxy.ask(msg, title || "提示", callback).addClass("alert");
};

//alert , error 的基类。
Boxy.ask = function (msg, title, callback) {
    if (!msg && (msg !== 0)) {
        if (callback) {
            callback({
            });
        }
    }

    return Boxy.html({
        html: "<div class='htmlPad boxy-msg wrap icon'>" + msg + "</div>",
        footer: "<input type=button value='确定' class='btnOK' />",
        title: title,
        callback: function (bxy) {
            bxy.find(".btnOK").bind("click", bxy, function (ev) {

                if (callback) {
                    var evOpener = bxy.data("openerEvent");

                    if (callback.call(jv.me(evOpener), bxy.getDivJson(), bxy, evOpener) === false) {
                        return false;
                    }
                }

                ev.data.Boxy("bye");
                ev.stopPropagation();
            });

            bxy.find("input:first").focus();
        }
    });
};

Boxy.html = function (options) {

    var p = $.extend(
    {
        html: false, title: "?", modal: true, callback: false, center: true, closeable: true
    },
        options
    );

    var boxy = new Boxy(p);

    if (p.callback) {
        p.callback(boxy);
    }

    $("input:first", boxy).focus();
    return boxy;
};

// returns true if a modal boxy is visible, false otherwise
Boxy.isModalVisible = function () {
    return jQuery('.boxy-modal-blackout').length > 0;
};


Boxy._nextZ = function () {
    if (!jv.zIndex) {
        jv.zIndex = 1337;
    }
    return ++jv.zIndex;
};



Boxy.Load = Boxy.load;
Boxy.LoadCard = Boxy.loadCard;
Boxy.LoadList = Boxy.loadList;
